import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_module/global/colors.dart';
import 'package:flutter_screenutil/screen_util.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: ProductDetailPage(),
      ),
    );
  }
}

class ProductDetailPage extends StatefulWidget {
  ProductDetailPage({Key key}) : super(key: key);

  @override
  _ProductDetailPageState createState() {
    return _ProductDetailPageState();
  }
}

class _ProductDetailPageState extends State<ProductDetailPage> {
  @override
  void initState() {
    super.initState();
    _loadData();
  }
  bool _display=false;
  void _loadData() async {
    EasyLoading.show(
      status: "Loading...",
      //duration: Duration(seconds: 2)
      //maskType: EasyLoadingMaskType.black,
    );
    await Future.delayed(Duration(milliseconds: 1000), () async {
      EasyLoading.dismiss();
      setState(() {
        _display=true;
      });
    });

  }
  @override
  void dispose() {
    super.dispose();
  }

  double _mAlpha = 0;
  ScrollController _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery.of(context).size.width,
          maxHeight: MediaQuery.of(context).size.height),
      designSize: Size(1080, 2340),
    );
    if(_display==true) {
      return SafeArea(
        child: Scaffold(
          body: Container(
            margin: EdgeInsets.only(bottom: 70),
            child: Stack(
              children: [
                MediaQuery.removePadding(
                  context: context,
                  removeTop: true,
                  child: NotificationListener(
                    onNotification: (notification) {
                      if (notification is ScrollUpdateNotification &&
                          notification.depth == 0) {
                        double d = notification.metrics.pixels / 200.0;
                        if (d < 0) {
                          d = 0;
                        } else if (d > 1) {
                          d = 1;
                        }
                        setState(() {
                          _mAlpha = d;
                        });
                      }
                    },
                    child: Container(
                      color: Color(0xff000B1F),
                      child: ListView(
                        controller: _scrollController,
                        children: [
                          Stack(
                            children: [
                              Container(
                                height: ScreenUtil().setHeight(1400),
                                width: double.infinity,
                                child: Image.asset(
                                  'assets/images/product_bg.png',
                                  width: ScreenUtil().screenWidth,
                                  fit: BoxFit.fitWidth,
                                ),
                              ),
                              Positioned(
                                top: ScreenUtil().setHeight(273),
                                left: ScreenUtil().setWidth(148),
                                child: Container(
                                  decoration: BoxDecoration(
                                    image: DecorationImage(
                                      image: NetworkImage(
                                        'http://photogz.photo.store.qq.com/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzAwS0MxrZm1k*1zjq0ea*xzKT8bI2OfaEDjQx7K*xuaaBcvpJIAE3XnW4QBIWwMRpQ!!/m&bo=xgLRAsYC0QIRADc!&rf=mood_app',
                                      ),
                                      fit: BoxFit.cover,
                                    ),
                                    color: Colors.white70,
                                    borderRadius:
                                    BorderRadius.all(Radius.circular(10)),
                                  ),
                                  width: ScreenUtil().setHeight(854),
                                  height: ScreenUtil().setHeight(854),
                                ),
                              ),
                            ],
                          ),
                          Container(
                            padding: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                            ),
                            height: ScreenUtil().setHeight(344),
                            margin: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(30),
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(0),
                            ),
                            decoration: BoxDecoration(
                              color: Color(0xff081327),
                              borderRadius: BorderRadius.all(Radius.circular(8)),
                            ),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '商品名称',
                                  style: TextStyle(
                                    fontSize: ScreenUtil().setSp(45),
                                    color: Colors.white70,
                                  ),
                                  textAlign: TextAlign.left,
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      '当前价格',
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color: Colors.white70,
                                      ),
                                      textAlign: TextAlign.left,
                                    ),
                                    Text.rich(
                                      TextSpan(
                                          children: [
                                            TextSpan(
                                              text: '',
                                              style: TextStyle(
                                                color: AppColors.primary,
                                                fontSize: ScreenUtil().setSp(30),
                                              ),
                                            ),
                                            TextSpan(
                                              text: '1.2 ETH',
                                              style: TextStyle(
                                                color: AppColors.primary,
                                                fontSize: ScreenUtil().setSp(60),
                                              ),
                                            ),
                                          ]
                                      ),
                                    ),
                                  ],
                                ),
                                Divider(color: Color(0xff1F273A),height: 0.5,),
                                Row(
                                  children: [
                                    ClipOval(
                                      child: Image.network(
                                          "https://img2.baidu.com/it/u=1652427738,3139747163&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
                                          width: ScreenUtil().setWidth(60),
                                          height: ScreenUtil().setWidth(60),
                                          fit: BoxFit.cover),
                                    ),
                                    SizedBox(width: ScreenUtil().setWidth(20),),
                                    Text(
                                      'Elbeau',
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color: Colors.white70,
                                      ),
                                      textAlign: TextAlign.left,
                                    ),
                                  ],
                                )
                              ],
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                            ),
                            height: ScreenUtil().setHeight(344),
                            margin: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(30),
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(0),
                            ),
                            decoration: BoxDecoration(
                              color: Color(0xff081327),
                              borderRadius: BorderRadius.all(Radius.circular(8)),
                            ),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                      'assets/images/left.png',
                                      width: ScreenUtil().setWidth(122),
                                      height: ScreenUtil().setHeight(42),
                                      fit: BoxFit.fitHeight,
                                    ),
                                    Text(
                                      '认证信息',
                                      style:TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color:AppColors.primary,
                                      ),
                                    ),
                                    Image.asset(
                                      'assets/images/right.png',
                                      width: ScreenUtil().setWidth(122),
                                      height: ScreenUtil().setHeight(42),
                                      fit: BoxFit.fitHeight,
                                    ),
                                  ],
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text(
                                      '区块链hash：QmPtdoRjb6jTVCmbNJz...',
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color: Colors.white70,
                                      ),
                                      textAlign: TextAlign.left,
                                    ),
                                    Container(
                                      width: ScreenUtil().setWidth(124),
                                      height: ScreenUtil().setHeight(68),
                                      decoration: BoxDecoration(
                                        color: AppColors.primary,
                                        borderRadius: BorderRadius.all(Radius.circular(5)),
                                      ),
                                      child: Center(
                                        child: Text(
                                          '复制',
                                          style:TextStyle(
                                            fontSize: ScreenUtil().setSp(40),
                                            color:Colors.black,
                                          ),
                                        ),
                                      ),
                                    ),
                                  ],
                                ),
                                Divider(color: Color(0xff1F273A),height: 0.5,),
                                Row(
                                  children: [
                                    Text(
                                      '发行份数：100',
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color: Colors.white70,
                                      ),
                                      textAlign: TextAlign.left,
                                    ),
                                    SizedBox(width: ScreenUtil().setWidth(160),),
                                    Text(
                                      '剩余份数：78',
                                      style: TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color: Colors.white70,
                                      ),
                                      textAlign: TextAlign.left,
                                    ),
                                  ],
                                )
                              ],
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                              ScreenUtil().setWidth(50),
                              ScreenUtil().setHeight(50),
                            ),

                            margin: EdgeInsets.fromLTRB(
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(30),
                              ScreenUtil().setWidth(30),
                              ScreenUtil().setHeight(0),
                            ),
                            decoration: BoxDecoration(
                              color: Color(0xff081327),
                              borderRadius: BorderRadius.all(Radius.circular(8)),
                            ),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                      'assets/images/left.png',
                                      width: ScreenUtil().setWidth(122),
                                      height: ScreenUtil().setHeight(42),
                                      fit: BoxFit.fitHeight,
                                    ),
                                    Text(
                                      '商品详情',
                                      style:TextStyle(
                                        fontSize: ScreenUtil().setSp(45),
                                        color:AppColors.primary,
                                      ),
                                    ),
                                    Image.asset(
                                      'assets/images/right.png',
                                      width: ScreenUtil().setWidth(122),
                                      height: ScreenUtil().setHeight(42),
                                      fit: BoxFit.fitHeight,
                                    ),
                                  ],
                                ),
                                SizedBox(height: ScreenUtil().setHeight(80),),
                                Image.network(        'http://photogz.photo.store.qq.com/psc?/V54ETsN62Rdw772wFsNq0jEkXI4LU2rF/05RlWl8gsTOH*Z17MtCBzAwS0MxrZm1k*1zjq0ea*xzKT8bI2OfaEDjQx7K*xuaaBcvpJIAE3XnW4QBIWwMRpQ!!/m&bo=xgLRAsYC0QIRADc!&rf=mood_app',
                                  width: double.infinity,
                                  fit: BoxFit.fitWidth,)
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ),
                Opacity(
                  opacity: _mAlpha,
                  child: Container(
                    height: 60,
                    decoration: BoxDecoration(color: Colors.white),
                    child: AppBar(
                      backgroundColor: Color(0xff000B1F),
                      leading: IconButton(
                        icon: Icon(Icons.arrow_back, color: Colors.white),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      ),
                      actions: [
                        IconButton(
                          icon: Icon(Icons.add, color: Colors.white),
                          onPressed: () {},
                        )
                      ],
                      centerTitle: true,
                      title: Text(
                        '商品详情',
                      ),
                    ),
                  ),
                ),
                Positioned(
                  left: 5,
                  top: 4,
                  child: IconButton(
                    icon: Icon(Icons.arrow_back, color: Colors.white),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                  ),
                ),
              ],
            ),
          ),
          bottomSheet: Container(
            height: 70,
            padding: EdgeInsets.fromLTRB(
              ScreenUtil().setWidth(50),
              ScreenUtil().setHeight(0),
              ScreenUtil().setWidth(50),
              ScreenUtil().setHeight(0),
            ),
            color: Color(0xff000B1F),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Container(
                  width: ScreenUtil().setWidth(68),
                  height: ScreenUtil().setHeight(122),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset(
                        'assets/images/icon_dianzan.png',
                        fit: BoxFit.fitWidth,
                      ),
                      Text(
                        '点赞',
                        style:TextStyle(
                          fontSize: ScreenUtil().setSp(33),
                          color:Colors.white70,
                        ),
                      )
                    ],
                  ),
                ),
                Container(
                  width: ScreenUtil().setWidth(68),
                  height: ScreenUtil().setHeight(122),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset(
                        'assets/images/icon_shoucang.png',
                        fit: BoxFit.fitWidth,
                      ),
                      Text(
                        '收藏',
                        style:TextStyle(
                          fontSize: ScreenUtil().setSp(33),
                          color:Colors.white70,
                        ),
                      )
                    ],
                  ),
                ),
                InkWell(
                  onTap: (){
                    Navigator.pushNamed(context, 'orderConfirm');
                  },
                  child: Container(
                    width: ScreenUtil().setWidth(274),
                    height: ScreenUtil().setHeight(122),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(30)),
                      color: AppColors.primary,
                    ),
                    child: Center(
                      child: Text(
                        '发起拼单',
                        style:TextStyle(
                          fontSize: ScreenUtil().setSp(50),
                          color:Colors.black,
                        ),
                      ),
                    ),
                  ),
                ),
                InkWell(
                  onTap: (){
                    Navigator.pushNamed(context, 'quequan');
                  },
                  child: Container(
                    width: ScreenUtil().setWidth(274),
                    height: ScreenUtil().setHeight(122),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(30)),
                      color: Color(0xcd44f1ef),
                    ),
                    child: Center(
                      child: Text(
                        '立即购买',
                        style:TextStyle(
                          fontSize: ScreenUtil().setSp(50),
                          color:Colors.black,
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    }else{
      return Container(
        width: 0,
        height: 0,
        color: AppColors.background,
      );
    }

  }
}
